var tblChild;
$(function () {
    tblChild = $('#tbl-child').DataTable(buildChildOptions());
    trCssEvent(tblChild);
    $("#btn-search-child").click(childSearch);
});

function buildChildOptions() {
    var options = {
        "autoWidth": false,
        "deferRender": true,
        "searching": false,
        "processing": true,
        "scrollX": true,
        "ordering": false,
        "serverSide": true,
        "language": {
            "url": "//cdn.datatables.net/plug-ins/1.10.12/i18n/Chinese.json"
        },
        "ajax": {
            "url": '/api/children',
            "type": 'POST',
            "dataType": 'json',
            data: function (params) {
                params['name'] = $("#child-name").val();
                params['tid'] = $("#teacherId").val();
                params['cid'] = $("#centerId").val();
            }
        },
        "columns": [{
            "data": "Name"
        }, {
            "data": "Sex"
        }, {
            "data": "Age"
        }, {
            "data": "Grade"
        }, {}],
        columnDefs: [{
            "targets": 4,
            "data": "Id",
            "render": function (data, type, row, meta, full) {
                return "<a  href='Course?childId=" + data + "' target='_blank'> 查看孩子的课程  </a>"

            }
        }, {"orderable": false, "targets": [0, 1, 3, 4]}
        ],
        "dom": "<'row'<'col-xs-12't>>r<'row'<'col-xs-2 lstyle'l><'col-xs-3'i><'col-xs-6  fright'p>>"
    };
    return options;
}

function childSearch() {
    $("#btn-search-child").attr("disabled", "disabled");
    tblChild.ajax.reload(function () {
        $("#btn-search-child").removeAttr("disabled");
    });
}


